﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Diagnostics;
using Microsoft.Xna.Framework.Content;

namespace XNADota.ContentPipeline.Terrain
{
    [ContentSerializerRuntimeType("XNADota.Terrain.Tree, XNADota")]
    public class TreeContent
    {
        public TreeContent(WCLoader Loader)
        {
            this.TreeType = Loader.ReadString(4);
            this.Variation = Loader.ReadInt32();
            this.Position = Loader.ReaderVector3();
            this.RotationAngle = Loader.ReadFloat();
            this.Scale = Loader.ReaderVector3();
            this.Flag = Loader.ReadByte();
            this.TreeLife = Loader.ReadByte();
            this.ItemTable = Loader.ReadInt32();
            Debug.Assert(this.ItemTable == -1);
            this.ItemCount = Loader.ReadInt32();
            Debug.Assert(this.ItemCount == 0);
            this.TreeId = Loader.ReadInt32();
        }

        public string TreeType;
        public int Variation;
        public Vector3 Position;
        public float RotationAngle;
        public Vector3 Scale;
        public byte Flag;
        public byte TreeLife;
        public int ItemTable;
        public int ItemCount;
        public int TreeId;
    }

    [ContentSerializerRuntimeType("XNADota.Terrain.WarCraftMapDoo, XNADota")]
    public class WarCraftMapDooContent
    {
        public WarCraftMapDooContent(WCLoader Loader)
        {
            Loader.ExpectTag("W3do");
            Version = Loader.ReadInt32();
            Debug.Assert(Version == 8);
            SubVersion = Loader.ReadInt32();
            Debug.Assert(SubVersion == 0x0000000B);
            TreeCount = Loader.ReadInt32();

            Trees = new TreeContent[TreeCount];
            for (int i = 0; i < Trees.Length; i++)
                Trees[i] = new TreeContent(Loader);

            Debug.Assert(Loader.ReadInt32() == 0);
            Debug.Assert(Loader.ReadInt32() == 0);
        }

        public int Version;
        public int SubVersion;
        public int TreeCount;
        public TreeContent[] Trees;
    }
}
